package com.tensquare.qa.dao;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.tensquare.qa.pojo.Problem;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 数据访问接口
 * @author Administrator
 *
 */
public interface ProblemDao extends JpaRepository<Problem,String>,JpaSpecificationExecutor<Problem>{

  @Query(value = "select * from tb_pl ,tb_problem where tb_pl.problemid = tb_problem.id and labelid = ? order by replytime desc"
    ,nativeQuery = true)//执行的是原生SQL语句
	public Page<Problem> newlist(String labelid, Pageable pageable);//最新回答

  @Query(value = "select * from tb_pl ,tb_problem where tb_pl.problemid = tb_problem.id and labelid = ? order by reply desc"
    ,nativeQuery = true)
	public Page<Problem> hotlist(String labelid, Pageable pageable);//最热回答

  @Query(value = "select * from tb_pl ,tb_problem where tb_pl.problemid = tb_problem.id and labelid = ? and reply=0 order by createtime desc"
    ,nativeQuery = true)//查出reply字段为0的行
  public Page<Problem> watilist(String labelid, Pageable pageable);//等待回答

}
